package com.nhim.cms.admin.server;

import java.util.List;

import com.nhim.cms.domain.ElementTemplate;
import com.nhim.cms.util.AppContext;
import com.nhim.cms.util.ElementTemplateManager;


public class ElementTemplateService  {

	public static List<ElementTemplate> findByElementDefinitionId(Integer id) {
		return ElementTemplateManager
		.getFromApplicationContext(AppContext.getApplicationContext()).findByElementDefinitionId(id);
		
	}

	public static Boolean remove(Integer id)
	{
		try {
			ElementTemplateManager
			.getFromApplicationContext(AppContext.getApplicationContext()).delete(id);
			 return true;
		} catch (Exception e) {

			e.printStackTrace();
			return false;
		}
	}
	public static Boolean isNameExist(Integer elementDefinitionId,String name)
	{
		ElementTemplate thisTemplate = ElementTemplateManager
		.getFromApplicationContext(AppContext.getApplicationContext()).findByNameAndElementDefinitionId(elementDefinitionId, name);
		if(thisTemplate != null)
			return true;
		return false;
		
	}
	public static ElementTemplate persit(ElementTemplate template)
	{
		try {
			return ElementTemplateManager
			.getFromApplicationContext(AppContext.getApplicationContext()).saveOrUpdate(template);
		} catch (Exception e) {
			
			e.printStackTrace();
			return null;
		}
	}

	

}
